package com.example.reactor;

import reactor.core.publisher.Mono;

public class MonoNullTest {
    public static void main(String[] args) {
        System.out.println("Testing Mono.justOrEmpty(null) behavior in different operators:");

        // 创建一个 Mono.justOrEmpty(null)，表示一个包含 null 的 Mono
        Mono<Object> nullMono = Mono.justOrEmpty(null);

        // 1. 测试 then 操作符
        nullMono
                .then(Mono.fromRunnable(() -> System.out.println("Entered then operator")))
                .subscribe();

        // 2. 测试 flatMap 操作符
        nullMono
                .flatMap(result -> {
                    System.out.println("Entered flatMap operator with result: " + result);
                    return Mono.just("FlatMap operator triggered");
                })
                .subscribe();

        // 3. 测试 delayUntil 操作符
        nullMono
                .delayUntil(result -> {
                    System.out.println("Entered delayUntil operator with result: " + result);
                    return Mono.just("Delayed operator triggered");
                })
                .subscribe();

        // 4. 测试 switchIfEmpty 操作符
        nullMono
                .switchIfEmpty(Mono.fromRunnable(() -> System.out.println("Entered switchIfEmpty operator")))
                .subscribe();
    }
}

